package com.itheima.dao;


import com.itheima.pojo.Blog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface BlogDao extends Mapper<Blog> {

    @Select("SELECT * FROM `t_tag` WHERE sort = (SELECT MAX(sort) FROM `t_tag` )")
    List<Blog> getHotTag();
    /**
     * 通过标签获取博客数量
     *
     * @return
     */
    @Select("SELECT tag_uid, COUNT(tag_uid) as count FROM  t_blog GROUP BY tag_uid")
    List<Map<String, Object>> getBlogCountByTag();

    /**
     * 通过分类获取博客数量
     *
     * @return
     */
    @Select("SELECT blog_sort_uid, COUNT(blog_sort_uid) AS count FROM  t_blog where status = 1 GROUP BY blog_sort_uid")
    List<Map<String, Object>> getBlogCountByBlogSort();

    /**
     * 获取一年内的文章贡献数
     *
     * @param startTime
     * @param nowTime
     * @return
     */
    @Select("SELECT DISTINCT DATE_FORMAT(create_time, '%Y-%m-%d') DATE, COUNT(uid) COUNT FROM t_blog WHERE 1=1 && status = 1 && create_time >= #{startTime} && create_time < #{nowTime} GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')")
    List<Map<String, Object>> getBlogContributeCount(String startTime, String nowTime);

    @Select("SELECT *  from t_blog  where status=1 and create_time between #{beginDate} and #{endDate}")
    List<Blog> findBlogByMonth(@Param("beginDate") String beginDate, @Param("endDate")  String endDate);

    @Select("select * from t_blog where tag_uid like concat('%',#{tagUid},'%')")
    List<Blog> selectByTagUid(String tagUid);
}
